package com.xinyu.controller;

import com.xinyu.service.IVProfileService;
import com.xinyu.vo.VProfileVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/profile")
public class VProfileController {

    @Autowired
    private IVProfileService profileService;

    @PostMapping("/upload")
    public ResponseEntity<?> uploadFile(@RequestParam("file") MultipartFile file) {
        try {
            Map<String, Object> result = profileService.processExcelFile(file);
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            return ResponseEntity.badRequest().body("Error processing file: " + e.getMessage());
        }
    }

    @GetMapping("/data/{fileId}")
    public ResponseEntity<List<VProfileVO>> getProcessedData(@PathVariable String fileId) {
        try {
            List<VProfileVO> data = profileService.getProcessedData(fileId);
            return ResponseEntity.ok(data);
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(null);
        }
    }
}